<?php $this->headLink()
->appendStylesheet($this->js('css/jquery.alerts.css'))
->appendStylesheet($this->js('css/tablesorter/default.css'))
->appendStylesheet($this->js('plugins/css/jquery.autocomplete.css'));
 $this->headScript()
->appendFile($this->js('plugins/jquery.form.js'))
->appendFile($this->js('plugins/jquery.blockUI.js'))
->appendFile($this->js('plugins/jquery.alerts.js'))
->appendFile($this->js('plugins/jquery.DOMWindow.js'))
->appendFile($this->js('plugins/jquery.printf.js'))
->appendFile($this->js('plugins/jquery.tablesorter.js'))
->appendFile($this->js('plugins/jquery.autocomplete.min.js'))
?>
<script type="text/javascript">
$(document).ready(function(){
    //顯示歷年紀錄錄
    listRecord();
    // 人數統計
    $("#selYear-element").append("<p id='countSex'></p>");

    // 初始化 movenewForm
    $("#movenewForm").ajaxForm({
        dataType:  'json',
        success: showResponse
    });

    // 更改年度
    $("#movenew-selYear").change(function(){
        if ($(this).val()=='') {
            $("#countSex").html('');
            return fasle;
        }
        $.getJSON('<?php echo $this->route("get-new-student-count")?>',{
            year: $(this).val()
            },function(data){
                var str = '<?php echo $this->translate('boy')?> : '+data.M+', <?php echo $this->translate('girl')?> : '+data.F
                +'<br/><?php echo $this->translate('new student total')?> : '+(data.count);
                $("#countSex").html(str);
            });
      });


     // 展開查詢
     $("#movenew-zoom-in").click(function(){
         $.openDOMWindow({
             loader:1,
             loaderImagePath:'animationProcessing.gif',
             loaderHeight:16,
             loaderWidth:17,
             width : 960,
             windowSourceID:'#movenew-list'
         });
     });

     //取消修改
     $("#movenew-CancelBtn").click(function(){
//          $("#movenewForm").attr('action','<?php echo $this->route('movenew-set')?>');
          $("#movenew-selYear").val('');
          $("#movenew-date").val('');
          $("#movenew-approve_date").val('');
          $("#movenew-approve_number").val('');
          $("#countSex").html('');
     });

     //儲存
     $("#movenew-SaveBtn").click(function(){
         $('#movenew-data').block({message:'<h1><?php echo $this->translate('Data setting ..')?></h1>',  border: '3px solid #f00'});
           $("#movenewForm").submit();
     });

});

// 儲存回應內容
function showResponse(res) {
    if (res.error) {
        var message = '';
        $.each(res.error,function(i,val){
            $.each(val,function(ii,vv){
                $("#"+i+"-"+ii).addClass('ui-state-error');
                $.each(vv,function(iii,vvv){
                    message += $("#"+ii+"-label label").html()+': '+ vvv+ "\n";
                });
            });
        });
        jAlert(message, '<?php echo $this->translate('checking errors')?>');

    }
    else{
        $(".ui-state-error").removeClass('ui-state-error ');
       // $("#selForm input:text").val('').attr('disabled','');
        //$("#movenew-SaveBtn").attr('disabled','true');
         listRecord();
    }
    $('#movenew-data').unblock();
}


// 列出歷年資料
function listRecord() {
    $.get('<?php echo $this->route("get-new-student-count-list")?>',function(data){
        $("#movenew-list").html(data);
    });
}


// 回填修改資料
function setMoveNewData(sn)
{
    $.getJSON('<?php echo $this->route("get-transfer-data-byid")?>',{sn:sn},function(data){
        $.each(data,function(i,v){
            $("#movenew-"+i).val(v);
        });
        $("#movenew-selYear").val(data.year);
        $("#movenew-selYear").trigger('change');
    });
}
</script>

<style>
#movenew-list{overflow: auto; height:350px; width:600px ;background:#ffe;border:thin solid #ccc;padding:3px;}
#movenew-list table {white-space: nowrap; text-align: center}
#movenew-list tbody tr {cursor: pointer;}
.trover {background-color: #ffccCC;}
.trclick {background-color: #DDffCC;}

</style>
<div id="movenew-data" class="ui-widget ui-content ui-corner-all">
<!-- 設定表單 -->
<div id="movenew-dataForm" style="float:left;width:250px">
<form action="<?php echo $this->route('movenew-set')?>" method="post"  id="movenewForm" >
<input type="button" id="movenew-SaveBtn" value="<?php echo $this->translate('save')?>" />
<input type="button" id="movenew-CancelBtn" value="<?php echo $this->translate('cancel')?>" />
<div style="border:#ccc thin solid; padding:5px;margin:5px">
<?php echo $this->form->selYear?>
<?php echo $this->form->date?>
<?php echo $this->form->approve_organ?>
<?php echo $this->form->approve_date?>
<?php echo $this->form->approve_word?>
<?php echo $this->form->approve_number?>
</div>
</form>
</div>
<!-- 列出歷年記錄 -->
<h2><span id="year-semester-span"></span> <?php echo $this->translate('all new student data')?>
<img  id="movenew-zoom-in" src="<?php echo $this->baseUrl?>/images/zoom-in.png"  style="margin-left:5px" />
</h2>
<div id="movenew-list" style="float:left; margin-left:10px">

</div>
<div style="clear:both"></div>
</div>